package model.effect;

import model.Executable;
import model.GameClock;
import model.entity.BasicEntity;
import model.entity.Entity;
import model.entity.stats.StatType;
import utilities.*;

public class SleepEffect extends Effect implements Archiveable
{
	
	public int timeToSleep;
	private Entity myEnt;
	/**
	 * @param name
	 * @param numLivesTaken
	 */
	public SleepEffect(String name, int theTimeToSleep)
	{
		super(name);
		this.timeToSleep = theTimeToSleep;
	}

	@Override
	public void doEffect(BasicEntity ent)
	{
		try{
			myEnt = ((Entity)ent);
			myEnt.setSleeping(true);
			
			GameClock.getInstance().schedule(100, new Executable() {
				public void execute() { myEnt.setSleeping(false); }
			});
			
		}catch (Exception e) {
			
		};
		
	}

	@Override
	public String toString()
	{
		return "SleepEffect [timeToSleep=" + timeToSleep + "]";
	}
	
	public Archive save() {
		Archive archive = super.save();
		
//		archive.putAttribute("numLivesTaken", Integer.toString(this.numLivesTaken));
		
		return archive;
	}
	
	public void load(Archive archive) {
		super.load(archive);
		
//		this.numLivesTaken = Integer.parseInt(archive.getAttribute("numLivesTaken"));
	}

}